namespace Vibstudio.NetConfigurator.Model
{
    #region Namespaces

    using System;
    using System.Collections.Generic;

    #endregion

    public class HttpConfigurationIdentityComparer : IEqualityComparer<HttpConfigurationIdentity>
    {
        #region Public Methods and Operators

        public bool Equals(HttpConfigurationIdentity x, HttpConfigurationIdentity y)
        {
            return (x.HostName.ToLower() == y.HostName.ToLower())
                   &&
                   (x.ResourceName.ToLower() == y.ResourceName.ToLower())
                   &&
                   (Enum.GetName(typeof(HttpSection), x.Section).ToLower() == Enum.GetName(typeof(HttpSection), y.Section).ToLower());
        }

        public int GetHashCode(HttpConfigurationIdentity obj)
        {
            int hash = 23
                       *
                       37
                       +
                       string.Format("{0}#{1}#{2}",
                                     Enum.GetName(typeof(HttpSection), obj.Section).ToLower(),
                                     obj.ResourceName.ToLower(),
                                     obj.HostName.ToLower()).GetHashCode();

            return hash;
        }

        #endregion
    }
}